package com.mcc.collect.opc.service;

import com.mcc.collect.cache.domain.PlcCache;
import com.mcc.common.config.ProjectConfig;
import org.eclipse.milo.opcua.sdk.client.OpcUaClient;
import org.eclipse.milo.opcua.sdk.client.api.identity.AnonymousProvider;
import org.eclipse.milo.opcua.sdk.client.api.identity.IdentityProvider;
import org.eclipse.milo.opcua.stack.core.security.SecurityPolicy;
import org.eclipse.milo.opcua.stack.core.types.structured.EndpointDescription;

import java.util.function.Predicate;


public interface IOpcUAClientService {

    default String getEndpointUrl() {
        return ProjectConfig.getOpcUrl();
    }

    default Predicate<EndpointDescription> endpointFilter() {
        return e -> true;
    }

    default SecurityPolicy getSecurityPolicy() {
        return SecurityPolicy.None;
    }

    default IdentityProvider getIdentityProvider() {
        return new AnonymousProvider();
    }

    void run(OpcUaClient client) throws Exception;

    void readConfig();

    void readNode(OpcUaClient client);

    void updateValue(String code, PlcCache plcCache, Object nodeValue);

    boolean writeValue(OpcUaClient client, String code, Object value);
}
